Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String conversion perf improvements + minor unrelated changes #54

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

louiswins
Copy link

The main change here is a rewrite of Guid::str to make only one call to snprintf and avoid string concatenation entirely. It just puts the bytes directly into a buffer and then copies that into the string. My microbenchmarks showed a 15-20% improvement in string conversion there. While this isn't the most common Guid operation it's a decent saving. And I would argue that the new code is a little more clear anyway.

I also snuck in some minor unrelated changes:

  • (Win32-specific) Explicitly discard the result of CoCreateGuid. MSDN says this is always S_OK but it's still marked _Check_result_ which can cause a warning if you don't, well, check the result.
  • Mark some helper functions static to give them internal linkage

Convert to string with one call to snprintf and no string concatenations
instead of 5 calls to snprintf and 8 concatenations. Microbenchmarks
indicate that this is approximately 17% faster (1.17 times as fast).
On MSDN it is marked as only being able to return S_OK, but in
combaseapi.h it is still marked _Check_result_. This will cause a
warning if you have them cranked up high enough.
This could theoretically open up some optimizations, but mostly it's
just good hygiene.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant